﻿using UnityEngine;
namespace CalmNine.Framework
{
    public interface IGameSave { }

    public class PlayerPrefsBoolVal : EventVal<bool>, IGameSave
    {
        public PlayerPrefsBoolVal(string saveKey, bool defaultValue = false)
        {
            mValue = PlayerPrefs.GetInt(saveKey, defaultValue ? 1 : 0) == 1;

            this.Register(value => PlayerPrefs.SetInt(saveKey, value ? 1 : 0));
        }
    }
    public class PlayerPrefsIntVal : EventVal<int>, IGameSave
    {
        public PlayerPrefsIntVal(string saveKey, int defaultValue = 0)
        {
            mValue = PlayerPrefs.GetInt(saveKey, defaultValue);

            this.Register(value => PlayerPrefs.SetInt(saveKey, value));
        }
    }
    public class PlayerPrefsFloatVal : EventVal<float>, IGameSave
    {
        public PlayerPrefsFloatVal(string saveKey, float defaultValue = 1.0f)
        {
            mValue = PlayerPrefs.GetFloat(saveKey, defaultValue);

            this.Register(value => PlayerPrefs.SetFloat(saveKey, value));
        }
    }

    public class PlayerPrefsStringVal : EventVal<string>, IGameSave
    {
        public PlayerPrefsStringVal(string saveKey, string defaultValue = "")
        {
            mValue = PlayerPrefs.GetString(saveKey, defaultValue);

            this.Register(value => PlayerPrefs.SetString(saveKey, value));
        }
    }
}